package com.liujit.upms.controller;

import cn.hutool.core.lang.tree.Tree;
import com.liujit.common.domain.params.BaseParams;
import com.liujit.common.domain.result.PageBean;
import com.liujit.upms.domain.params.SysOrgParams;
import com.liujit.upms.domain.query.SysOrgQuery;
import com.liujit.upms.domain.query.SysOrgTreeQuery;
import com.liujit.upms.domain.result.SysOrgResult;
import com.liujit.upms.service.SysOrgService;
import com.liujit.validator.group.AddGroup;
import com.liujit.validator.group.ModifyGroup;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description 系统机构管理接口
 * @Author liujun
 * @Date 2021-07-02 15:00:39
 */
@RequiredArgsConstructor
@Api(tags = "系统机构管理接口")
@RestController
@RequestMapping("/sys/org")
public class SysOrgController {

    private final SysOrgService sysOrgService;

    @ApiOperation(value = "分页查询", notes = "根据系统机构分页查询条件，分页查询系统机构列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "query", value = "系统机构分页查询条件", dataType = "SysOrgQuery", dataTypeClass = SysOrgQuery.class, paramType = "query") })
    @GetMapping("/getPage")
    public PageBean<SysOrgResult> getPage(SysOrgQuery query) {
        return sysOrgService.getPage(query);
    }

    @ApiOperation(value = "添加", notes = "根据系统机构添加请求参数，添加系统机构")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "params", value = "系统机构添加请求参数", dataType = "SysOrgParams", dataTypeClass = SysOrgParams.class, paramType = "body") })
    @PostMapping("add")
    public Boolean add(@RequestBody @Validated(AddGroup.class) SysOrgParams params) {
        return sysOrgService.save(params);
    }

    @ApiOperation(value = "修改", notes = "根据系统机构修改请求参数，修改系统机构")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "params", value = "系统机构修改请求参数", dataType = "SysOrgParams", dataTypeClass = SysOrgParams.class, paramType = "body") })
    @PostMapping("/modify")
    public Boolean modify(@RequestBody @Validated(ModifyGroup.class) SysOrgParams params) {
        return sysOrgService.save(params);
    }

    @ApiOperation(value = "查询", notes = "根据系统机构id，查询系统机构")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "系统机构id", dataType = "Long", dataTypeClass = Long.class, paramType = "query") })
    @GetMapping("/get")
    public SysOrgResult get(Long id) {
        return sysOrgService.get(id);
    }

    @ApiOperation(value = "查询详情", notes = "根据系统机构id，查询系统机构")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "系统机构id", dataType = "Long", dataTypeClass = Long.class, paramType = "query") })
    @GetMapping("/getDetail")
    public SysOrgResult getDetail(Long id) {
        return sysOrgService.getDetail(id);
    }

    @ApiOperation(value = "删除", notes = "根据系统机构删除请求参数，删除系统机构")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "params", value = "系统机构删除请求参数", dataType = "BaseParams", dataTypeClass = BaseParams.class, paramType = "body") })
    @PostMapping("/del")
    public Boolean del(@RequestBody BaseParams params) {
        return sysOrgService.del(params);
    }

    @ApiOperation(value = "启用", notes = "根据系统机构启用请求参数，启用系统机构")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "params", value = "系统机构启用请求参数", dataType = "BaseParams", dataTypeClass = BaseParams.class, paramType = "body") })
    @PostMapping("/enabled")
    public Boolean enabled(@RequestBody BaseParams params) {
        return sysOrgService.enabled(params);
    }

    @ApiOperation(value = "禁用", notes = "根据系统机构禁用请求参数，禁用系统机构")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "params", value = "系统机构禁用请求参数", dataType = "BaseParams", dataTypeClass = BaseParams.class, paramType = "body") })
    @PostMapping("/disabled")
    public Boolean disabled(@RequestBody BaseParams params) {
        return sysOrgService.disabled(params);
    }

    @ApiOperation(value = "查询机构树形列表", notes = "根据系统机构树查询条件，查询机构树形列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "query", value = "系统机构树查询条件", dataType = "SysOrgTreeQuery", dataTypeClass = SysOrgTreeQuery.class, paramType = "query") })
    @GetMapping("/getTree")
    public List<Tree<Long>> getTree(SysOrgTreeQuery query) {
        return sysOrgService.getTree(query);
    }
}
